dz.news = {
	aFollow : [],
	aLike		: []
}

dz.news.follow = function (obj){
	if (obj.hasClass('loading')) return;
	
	var news_id = $(obj).attr('news-id');
	var task = $(obj).hasClass('active')?'unfollow':'follow';
	
	obj.addClass('loading');
	$('.btn-news-follow[news-id='+news_id+']').toggleClass('active');
	$.ajax({
		type	: 'POST',
		url		:	dz.l('news/follow'),
		data	: {
			news_id	: news_id,
			task		: task
		},
		success	: function (res){			
			obj.removeClass('loading');
			if (parseInt(res['code'])==1){
				
			}else{
				alert(res['mess']);
				$('.btn-news-follow[news-id='+news_id+']').toggleClass('active');
			}
		},
		dataType	: 'json'
	});
}

dz.news.like = function (obj){
	if (obj.hasClass('loading')) return;
	
	var news_id = $(obj).attr('news-id');
	var task = $(obj).hasClass('active')?'unfollow':'follow';
	
	obj.addClass('loading');
	$('.btn-news-like[news-id='+news_id+']').toggleClass('active');
	$.ajax({
		type	: 'POST',
		url		:	dz.l('news/like'),
		data	: {
			news_id	: news_id,
			task		: task
		},
		success	: function (res){			
			obj.removeClass('loading');
			if (parseInt(res['code'])==1){				
			}else{
				alert(res['mess']);
				$('.btn-news-like[news-id='+news_id+']').toggleClass('active');
			}
		},
		dataType	: 'json'
	});
}

dz.news.updateFollow = function (aFollow){
	for (i in aFollow){
		$('.btn-news-follow[news-id='+aFollow[i]+']').addClass('active');
	}
}

dz.news.updateLike = function (aLike){
	for (i in aLike){
		$('.btn-news-like[news-id='+aLike[i]+']').addClass('active');
	}
}

$(document).ready(function (){	
	$('.btn-news-follow').click(function (e){
		e.preventDefault();
		dz.news.follow($(this));
	});
	
	$('.btn-news-like').click(function (e){
		e.preventDefault();
		dz.news.like($(this));
	});
})